<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * City Controller.
 * 
 * @class     City
 * @author    Iqbal
 * @version   1.0.0
 * @copyright Copyright (c) 2014 IPPI (http://www.ippi.or.id)
 */
class city extends CI_Controller {
    /**
	 * Constructor.
	 */
    function __construct() {
        parent::__construct();
        
        // Load model
        $this->load->model('admin_model', 'm_admin', TRUE);
        $this->load->model('model_city', 'm_city', TRUE);
    }

    /**
	 * Get City function.
     * @return AJAX String
	 */
    function get_city(){
        // Set ID state param
        $idstate = $this->input->post('stateid');
        
        // Check state ID param
        if($idstate == "" || !isset($_POST['stateid'])){
            $output = array(
                'status'    =>  0,
                'msg'       =>  'ID State cannot be blank'
            );
            echo json_encode($output);
        }
        else{
            $count = $this->m_city->count_city_by_idstate($idstate);
            if($count > 0){
                $list = $this->m_city->get_city_by_idstate($idstate);
                $output = array(
                    'status'    =>  1,
                    'list'      =>  $list
                );
                echo json_encode($output);
            }
            else{
                $output = array(
                    'status'    =>  0,
                    'msg'       =>  'Wrong ID State'
                );
                echo json_encode($output);
            }
        }
    }
}

/* End of file city.php */
/* Location: ./application/controllers/city.php */